#include <bits/stdc++.h>
#include "library.h"
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)
#define pb push_back
using namespace std;

vector < int > Q, res;
set < int > s;

int n;

int get(int cnt, int x) {
	auto it = s.begin(); if(x) Q[x - 1] = 1;
	rep(i, 1, cnt) Q[*it - 1] = 1, it++;
	//	cerr << "! " << x << " : " << cnt << " | " ; for(auto v : Q) cerr << v << " "; cerr << endl;
	int res = Query(Q);
	it = s.begin();
	rep(i, 1, cnt) Q[*it - 1] = 0, it++;
	if(x) Q[x - 1] = 0;
	//	cerr << res << endl;
	return res;
}

int eget(int cnt) {
	auto it = s.begin();
	rep(i, 2, cnt) it++;
	return *it;
}

void solve(int x) {
	int l = 1, r = s.size();
	rep(i, 1, n) Q[i - 1] = 0;
	while(l <= r) {
		int mid = l + r >> 1;
		//		cerr << mid << " : " << x << " " << get(mid, x) << " " << get(mid, 0) << endl;
		if(get(mid, x) <= get(mid, 0)) r = mid - 1;
		else l = mid + 1; 
	} /*cerr <<"R : "<< l << endl;*/ res.pb(eget(l)); s.erase(res.back());
}

void Solve(int N) {
	n = N; Q.resize(n); rep(i, 1, n) s.insert(i), Q[i - 1] = 1;
	if(n == 1) { res.pb(1); Answer(res); return; }
	rep(i, 1, n) {
		Q[i - 1] = 0;
		if(Query(Q) == 1) { res.pb(i); s.erase(i); break; }
		Q[i - 1] = 1;
	}
	while(res.size() < n) solve(res.back());
	//for(auto v : res) cerr << v << " "; cerr << endl;
	Answer(res);
}
